﻿<Page
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
    x:Class="Robert.TwitBy.Views.MainPage"
	x:Name="me"
	WindowTitle="Tweets"
    MinWidth="200" MinHeight="250"
	>
    <Page.Resources>
        <CollectionViewSource Source="{Binding Tweets}" x:Key="TweetsView">
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="DateCreated" Direction="Descending"/>
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
        <Storyboard x:Key="LoadToolbarStoryboard">
            <DoubleAnimationUsingKeyFrames BeginTime="0:0:0.25" Storyboard.TargetName="Toolbar" Storyboard.TargetProperty="(FrameworkElement.Height)">
                <SplineDoubleKeyFrame KeyTime="0:0:0.00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="0:0:0.50" Value="30"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="0:0:1.00" Storyboard.TargetName="Toolbar" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="0:0:0.00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="0:0:0.15" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="UnloadToolbarStoryboard">
            <DoubleAnimationUsingKeyFrames BeginTime="0:0:0.25" Storyboard.TargetName="Toolbar" Storyboard.TargetProperty="(FrameworkElement.Height)">
                <SplineDoubleKeyFrame KeyTime="0:0:0" Value="30"/>
                <SplineDoubleKeyFrame KeyTime="0:0:0.50" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetName="Toolbar" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="0:0:0" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="0:0:0.15" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Page.Resources>
	<Grid x:Name="LayoutRoot" Margin="0">
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="*"/>
			<RowDefinition Height="Auto" MaxHeight="75"/>
		</Grid.RowDefinitions>
		<Border BorderThickness="0,0,0,2" Margin="0,0,0,1">
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FF90E5D0" Offset="1"/>
                    <GradientStop Color="#FF007A1E"/>
                </LinearGradientBrush>
            </Border.Background>
            <StackPanel>
                <StackPanel Orientation="Horizontal" 
                            Margin="0">
                    <RadioButton Padding="4" ToolTip="Get the tweets on your home timeline. (Crtl+1)"
                                 Margin="3" Template="{DynamicResource RadioButtonControlTemplate}"
                                 IsChecked="{Binding IsHomeCheck}"
                                 Command="{Binding LoadHomeCommand}">
                        <Image Style="{StaticResource ImageStyle}"
                               Source="/Images/Home.png"
                               Width="25" Height="25"/>
                    </RadioButton>
                    <RadioButton Padding="4" ToolTip="Get the tweets you sent. (Ctrl+2)"
                                 Margin="3" Template="{DynamicResource RadioButtonControlTemplate}" 
                                 IsChecked="{Binding IsYouCheck}"
                                 Command="{Binding LoadYourCommand}">
                        <Image Style="{StaticResource ImageStyle}"
                               Source="/Images/Public.png"
                               Width="25" Height="25"/>
                    </RadioButton>
                    <RadioButton Padding="4" ToolTip="Get the tweets mentioning you. (Ctrl+3)"
                                 Margin="3" Template="{DynamicResource RadioButtonControlTemplate}" 
                                 IsChecked="{Binding IsMentionCheck}"
                                 Command="{Binding LoadMentionsCommand}">
                        <Image Style="{StaticResource ImageStyle}"
                               Source="/Images/Mentions.png"
                               Width="25" Height="25"/>
                    </RadioButton>
                    <RadioButton Padding="4" ToolTip="Get your direct messages. (Ctrl+4)"
                                 Margin="3" Template="{DynamicResource RadioButtonControlTemplate}" 
                                 IsChecked="{Binding IsDirectCheck}"
                                 Command="{Binding LoadDirectsCommand}">
                        <Image Style="{StaticResource ImageStyle}"
                               Source="/Images/Directs.png"
                               Width="25" Height="25"/>
                    </RadioButton>
                    <RadioButton Padding="4" ToolTip="Log out. (Requires application restart.)"
                                 Margin="3" Template="{DynamicResource RadioButtonControlTemplate}"
                                 Command="{Binding LogOutCommand}">
                        <Image Style="{StaticResource ImageStyle}"
                               Source="/Images/delete.png"
                               Width="25" Height="25"/>
                    </RadioButton>
                    <Button Padding="4" ToolTip="Refresh current view. (Ctrl+F5)"
                            Margin="3" Template="{DynamicResource RefreshButtonControlTemplate}"
                            Command="{Binding RefreshTimelineCommand}">
                        <Image Style="{StaticResource ImageStyle}"
                               Source="/Images/retweet.png"
                               Width="25" Height="25"/>
                    </Button>
                </StackPanel>
                <Border BorderThickness="0,2,0,0" BorderBrush="White" 
                        Margin="3,0,3,3">
                    <StackPanel x:Name="Toolbar" 
                                Grid.Row="0" 
                                Height="0" Width="Auto" 
                                VerticalAlignment="Bottom" 
                                Orientation="Horizontal" Opacity="0">
                        <Button ToolTip="Favorite this tweet. (Ctrl+F)"
                                Margin="3"
                                Width="{Binding ElementName=Toolbar, Path=Height}" 
                                Template="{DynamicResource ButtonControlTemplate}"
                                Command="{Binding FavoriteCommand}">
                            <Image Style="{StaticResource ButtonImageStyle}"
                                   Source="/Images/favorite.png" 
                                   Width="{Binding ElementName=Toolbar, Path=Height}"/>
                        </Button>
                        <Button ToolTip="Reply to this tweet. (Ctrl+R)"
                                Margin="3"
                                Width="{Binding ElementName=Toolbar, Path=Height}"
                                Template="{DynamicResource ButtonControlTemplate}"
                                Command="{Binding ReplyToCommand}">
                            <Image Style="{StaticResource ButtonImageStyle}"
                                   Source="/Images/Mentions.png"
                                   Width="{Binding ElementName=Toolbar, Path=Height}"/>
                        </Button>
                        <Button ToolTip="Retweet this tweet. (Ctrl+W)"
                                Margin="3"
                                Width="{Binding ElementName=Toolbar, Path=Height}"
                                Template="{DynamicResource ButtonControlTemplate}"
                                Command="{Binding RetweetCommand}">
                            <Image Style="{StaticResource ButtonImageStyle}"
                                   Source="/Images/retweet.png"
                                   Width="{Binding ElementName=Toolbar, Path=Height}"/>
                        </Button>
                        <Button ToolTip="Send direct message to user. (Ctrl+D)"
                                Margin="3"
                                Width="{Binding ElementName=Toolbar, Path=Height}"
                                Template="{DynamicResource ButtonControlTemplate}"
                                Command="{Binding DirectMessageCommand}">
                            <Image Style="{StaticResource ButtonImageStyle}"
                                   Source="/Images/Directs.png"
                                   Width="{Binding ElementName=Toolbar,Path=Height}"/>
                        </Button>
                        <Button ToolTip="Delete this tweet. (Delete)"
                                Margin="3"
                                Width="{Binding ElementName=Toolbar, Path=Height}"
                                Template="{DynamicResource ButtonControlTemplate}"
                                Command="{Binding DeleteCommand}">
                            <Image Style="{StaticResource ButtonImageStyle}"
                                   Source="/Images/delete.png"
                                   Width="{Binding ElementName=Toolbar, Path=Height}"/>
                        </Button>
                    </StackPanel>
                </Border>
            </StackPanel>
        </Border>
        
        <ListBox x:Name="tweetsListBox" 
                 Margin="3,0,0,3" 
                 Grid.Row="1" 
                 Background="{x:Null}"
                 ItemsSource="{Binding Source={StaticResource TweetsView}}" 
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                 ScrollViewer.CanContentScroll="True"
                 ItemTemplate="{DynamicResource Tweet}" 
                 ItemContainerStyle="{DynamicResource ListBoxItemStyle}"
                 SelectedItem="{Binding SelectedItem,Mode=TwoWay}" BorderBrush="White"/>
		<Grid Margin="3,0,3,3" 
              Grid.Row="2" 
              VerticalAlignment="Bottom">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="*"/>
				<ColumnDefinition Width="Auto"/>
			</Grid.ColumnDefinitions>
            <TextBox x:Name="tweetTextBox" 
                     TextWrapping="Wrap" 
                     SpellCheck.IsEnabled="True" 
                     ScrollViewer.VerticalScrollBarVisibility="Auto"
                     MaxHeight="75" 
                     VerticalAlignment="Bottom" Margin="0"
                     ToolTip="Just type your tweet here and press Enter to update."
                     Text="{Binding TweetMessage, UpdateSourceTrigger=PropertyChanged}"/>
            <Label VerticalAlignment="Stretch" 
                   BorderThickness="0" 
                   Margin="3,0,3,0" 
                   Grid.Column="1" 
                   HorizontalAlignment="Right"
                   MaxHeight="25"
                   Content="{Binding Text, Converter={StaticResource RemainingCharsConverter}, ElementName=tweetTextBox}">
                <Label.ToolTip>
                    <DockPanel>
                        <Label DockPanel.Dock="Left"
                               Content="Rate limit status:"/>
                        <Label DockPanel.Dock="Left"
                               Content="{Binding RateLimitStatus, StringFormat='{}{0} remaining hits.'}"/>
                        <Label DockPanel.Dock="Left"
                               Content=" remaining hits."/>
                    </DockPanel>
                </Label.ToolTip>
            </Label>
        </Grid>
	</Grid>
</Page>